package com.anxin.registerManagement.controller;

import com.alibaba.fastjson.JSONObject;
import com.anxin.registerManagement.bean.jo.SceneSearchJo;
import com.anxin.registerManagement.bean.persist.SceneDist;
import com.anxin.registerManagement.service.SceneDistService;
import com.anxin.registerManagement.util.Assert;
import com.anxin.registerManagement.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author anxin
 * @date 2022/3/30 19:34
 */
@RestController
@RequestMapping("/scenedists")
public class SceneDistController {

    private static final Logger LOGGER = LoggerFactory.getLogger(SceneDistController.class);

    @Autowired
    private SceneDistService sceneDistService;

    @PostMapping("/create")
    public ResultUtil create(@RequestBody SceneDist sceneDist) {
        LOGGER.info("场景距离查询：{}", JSONObject.toJSONString(sceneDist));
        sceneDistService.createDist(sceneDist);
        return ResultUtil.success();
    }

    @PostMapping("/update")
    public ResultUtil update(@RequestBody SceneDist sceneDist) {
        LOGGER.info("场景距离添加：{}", JSONObject.toJSONString(sceneDist));
        Assert.notNull(sceneDist.getId(), "id不能为空");
        sceneDistService.updateDist(sceneDist);
        return ResultUtil.success();
    }

    @PostMapping("/delete")
    public ResultUtil delete(@RequestParam("id") List<Integer> id) {
        Assert.notNull(id, "id不能为空");
        LOGGER.info("删除场景距离id：{}", id);
        sceneDistService.deleteDist(id);
        return ResultUtil.success();
    }

    @GetMapping("/getDistById")
    public ResultUtil getDistById(@RequestParam("id") Integer id) {
        Assert.notNull(id, "id不能为空");
        LOGGER.info("查询场景距离列表通过场景id：{}", id);
        return ResultUtil.success(sceneDistService.getDistById(id));
    }


}
